package com.fowo.api.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fowo.api.common.util.RequestUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;

/**
 * 系统登录日志
 */
@Schema(title = "系统登录日志")
@TableName("sys_login_log")
@Data
public class SysLoginLog {

    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    private Long userId;

    private String ip;

    private String userAgent;

    private Date loginTime;

    public static SysLoginLog createWithUserId(Long userId) {
        SysLoginLog sysLoginLog = new SysLoginLog();
        sysLoginLog.setLoginTime(new Date());
        sysLoginLog.setIp(RequestUtils.getRemoteAddr());
        sysLoginLog.setUserAgent(RequestUtils.getUserAgent());
        sysLoginLog.setUserId(userId);
        return sysLoginLog;
    }
}
